package test;

import java.util.Scanner;

/**
 * @author 郝雷蒙
 * @Description
 * @date 2020/12/1 11:05
 */
public class AAA {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int array[] = { 23,12,47,89,36,27,38,75,48,64 };

        for (int i = 0; i < 10; i++) {
            for (int j=i+1; j < 10; j++) {
                if (array[i] > array[j]){
                    int a=0 ;
                    a = array[i];
                    array[i] = array[j];
                    array[j] = a;

                }
            }
        }
        for (int i = 0; i < 10; i++) {
            System.out.print(array[i]);
            System.out.println();
        }

        System.out.println("请输入你要查找的数");
        int B = sc.nextInt();
         int min =0;                //最小下标
         int max = array.length-1;  //最大下标
         int mid = 0;                //中间下标


        while (min <max){
            mid =(min+max)/2;
            if (array[mid]>B){   //B在mid的左边
                max = mid-1;     //改变最大下标
            }else if (array[mid]<B){    //B在mid的右边
                min = mid+1;            //改变最小下标
            }else {
                System.out.println(mid);
                break;
            }
        }



    }
}

